package com.mdd.admin.controller.setting;

import com.mdd.admin.vo.setting.TransactionSettingVo;
import com.mdd.common.constant.GlobalConstant;
import com.mdd.common.utils.ConfigUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 系统交易设置
 */
@Api(tags = "系统交易设置")
@RestController("settingTransactionController")
@RequestMapping("api/setting/transaction")
public class TransactionController {


    /**
     * 查询交易设置
     *
     * @return Object
     * @author fzr
     */
    @ApiOperation(value = "系统交易设置 - 查询交易设置")
    @GetMapping("")
    public TransactionSettingVo transactionDetail() {
        Map<String, String> map = ConfigUtil.get(GlobalConstant.TRANSACTION_SETTING);
        TransactionSettingVo vo = new TransactionSettingVo();
        vo.setCancelUnpaidOrders(map.get(GlobalConstant.CANCEL_UNPAID_ORDERS));
        vo.setVerificationOrders(map.get(GlobalConstant.VERIFICATION_ORDERS));
        vo.setCancelUnpaidOrdersTimes(map.get(GlobalConstant.CANCEL_UNPAID_ORDERS_TIMES));
        vo.setVerificationOrdersTimes(map.get(GlobalConstant.VERIFICATION_ORDERS_TIMES));
        vo.setIsAuthDispatch(map.get(GlobalConstant.IS_AUTH_DISPATCH));
        return vo;
    }

    /**
     * 设置交易
     *
     * @return Object
     * @author fzr
     */
    @ApiOperation(value = "系统交易设置 - 设置交易")
    @PostMapping("")
    public void setTransaction(@RequestBody TransactionSettingVo vo) {
        ConfigUtil.set(GlobalConstant.TRANSACTION_SETTING, GlobalConstant.VERIFICATION_ORDERS, vo.getVerificationOrders());
        ConfigUtil.set(GlobalConstant.TRANSACTION_SETTING, GlobalConstant.VERIFICATION_ORDERS_TIMES, vo.getVerificationOrdersTimes());
        ConfigUtil.set(GlobalConstant.TRANSACTION_SETTING, GlobalConstant.CANCEL_UNPAID_ORDERS, vo.getCancelUnpaidOrders());
        ConfigUtil.set(GlobalConstant.TRANSACTION_SETTING, GlobalConstant.CANCEL_UNPAID_ORDERS_TIMES, vo.getCancelUnpaidOrdersTimes());
        ConfigUtil.set(GlobalConstant.TRANSACTION_SETTING, GlobalConstant.IS_AUTH_DISPATCH, vo.getIsAuthDispatch());
    }
}
